What you’ll build
- A CrewAI agent that returns JSON actions instead of calling backend APIs.
- A tool definition that keeps action payloads predictable.
- A
/kickoffstream that includestool_*events so the client can map actions. - A CometChat AI Agent entry that routes traffic to this CrewAI service.
Prerequisites
- CrewAI project + FastAPI stream from crew-ai.mdx
- Frontend capable of handling action payloads (UI Kit export or custom UI)
- Optional:
canvas-confettior your own action handlers
Steps
1
Define allowed actions
Decide on a small set of actions your UI will accept (e.g.,
open_product, show_confetti, toggle_theme).2
Create a CrewAI tool
Return structured JSON with action
name and parameters. Keep the schema narrow to avoid unsafe payloads.3
Instruct the agent
In the backstory, explain when to trigger each action and to keep text responses short when actions are returned.
4
Handle on the client
In your widget or UI Kit export, map
tool_call_* + tool_result events to actual UI functions (e.g., fire confetti, navigate).Sample action tool
src/crew_demo/tools/confetti_action.py
crew.py and add to the agent’s tool list alongside any other actions.
Agent configuration
src/crew_demo/config/agents.yaml
src/crew_demo/config/tasks.yaml
Client-side handling
- Listen for
tool_call_start/tool_call_argsto show “running action…” states. - Parse
tool_resultJSON and map theactionname to a handler. - Keep handlers idempotent and validate parameters on the client before executing.
Connect to CometChat
Use the same/kickoff endpoint as your CrewAI project. In Dashboard → AI Agents:
- Provider: CrewAI
- Agent ID:
ui_assistant - Deployment URL: your
/kickoff - (Optional) Suggested prompts: “Launch confetti”, “Open the product page for sku-123”